package com.andy.sqlSession;

import com.andy.config.XmlConfigBuilder;
import com.andy.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    private Configuration configuration;

    public SqlSessionFactoryBuilder() {
        this.configuration = new Configuration();
    }

    public SqlSessionFactory build(InputStream inputStream) throws DocumentException, PropertyVetoException, ClassNotFoundException {
        //解析配置文件
        XmlConfigBuilder xmlConfigBuilder = new XmlConfigBuilder(configuration);
        xmlConfigBuilder.parseConfigration(inputStream);

        //创建sqlSeesionFactory并返回
        return new DefaultSqlSessionFactory(configuration);
    }
}
